<script setup lang="ts">
// 去首页
import router from "@/router";
import { onBeforeUnmount, onMounted, onUnmounted, ref } from "vue";
import * as moment from "moment/moment";

// 存储当前时间
let nowTime = ref(moment().format("YYYY-MM-DD HH:mm:ss"));

// 定时器
let timer = ref(0);

const toHome = () => {
  router.push("/home");
};

onMounted(() => {
  // 组件创建时，开启定时器
  timer = setInterval(() => {
    nowTime.value = moment().format("YYYY-MM-DD HH:mm:ss");
  }, 1000);
});

onBeforeUnmount(() => {
  // 组件销毁时，清除定时器
  clearInterval(timer.value);
});

defineOptions({
  name: "Top",
});
</script>

<template>
  <div class="top">
    <div class="left">
      <span class="lbtn" @click="toHome"> 首页 </span>
    </div>
    <div class="center">
      <div class="title">智慧旅游可视化大数据</div>
    </div>
    <div class="right">
      <span class="rbtn"> 统计报告 </span>
      <span class="rtime"> 当前时间:{{ nowTime }} </span>
    </div>
  </div>
</template>

<style scoped lang="scss">
.top {
  width: 100%;
  height: 50px;
  display: flex;
  .left {
    flex: 1;
    background: url("../../images/dataScreen-header-left-bg.png") no-repeat;
    background-size: cover;
    .lbtn {
      width: 100px;
      height: 50px;
      float: right;
      background: url("../../images/dataScreen-header-btn-bg-l.png") no-repeat;
      background-size: 100% 100%;
      text-align: center;
      line-height: 50px;
      color: #29fcff;
    }
  }
  .center {
    flex: 2;
    .title {
      width: 100%;
      height: 74px;
      background: url("../../images/dataScreen-header-center-bg.png") no-repeat;
      background-size: cover;
      text-align: center;
      line-height: 74px;
      color: #29fcff;
      font-size: 30px;
    }
  }
  .right {
    flex: 1;
    background: url("../../images/dataScreen-header-right-bg.png") no-repeat;
    background-size: cover;
    display: flex;
    justify-content: space-between;
    .rbtn {
      width: 100px;
      height: 50px;
      background: url("../../images/dataScreen-header-btn-bg-r.png") no-repeat;
      background-size: 100% 100%;
      text-align: center;
      line-height: 50px;
      color: #29fcff;
    }
    .rtime {
      height: 50px;
      text-align: center;
      line-height: 50px;
      color: #29fcff;
      margin-right: 100px;
    }
  }
}
</style>
